package com.torinosrc;

/**
 * <b><code>Write</code></b>
 * <p/>
 * Write
 * <p/>
 * <b>Creation Time:</b> Mon Feb 20 14:52:30 CST 2017.
 *
 * @author lvxin
 * @version 0.0.1
 * @since generate 0.0.1
 */
import java.io.*;

public class Write {
    public static void main(String[] args) {
        write("D:\\Jason\\gen", "hello");
    }

    public static void write(String path, String content) {
        String s = new String();
        String s1 = new String();

        try {
            File f = new File(path);

            if (f.exists()) {
                System.out.println("文件存在");
            } else {
                System.out.println("文件不存在，正在创建...");
                if (f.createNewFile()) {
                    System.out.println("文件创建成功！");
                } else {
                    System.out.println("文件创建失败！");
                }
            }

            BufferedReader input = new BufferedReader(new FileReader(f));

            input.close();
            s1 += content;
            BufferedWriter output = new BufferedWriter(new FileWriter(f));
            output.write(s1);
            output.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}